
void Clock_close(Window*);

void Clock_dispose(Window* self);

void Clock_draw(Window* self);

void onTimer(Timer* self);

class Clock : public Form
{
  public:
  
  DynamicObject<Timer>* timer;
  
  void init(DynamicObject<Window>* self){

    Form::init(self);
    id = 123;
    height = 60;
    width = 220;
    pos_x = 1024 - width - 10;
    pos_y = 768 - height - 10;
    //b->text="timer";
    color = getRGB565(0x00FF0000);
    title="time";
    pOnClose = Clock_close;

    pDispose = Clock_dispose;
    pDraw = Clock_draw;
    {
      timer = DynamicMem::inst->dMalloc<Timer>("timer");
      timer->obj->interval = 1000;//ms
      timer->obj->nextTick = 0;//ms
      timer->obj->pOnTime = onTimer;
      ::windows->obj->addTimer(timer);
    }
  }

  void draw(){
    Form::draw();
    Stream* s = getStream(5, 22, 200, 200);
    char datetime[8];
    //0 sec
    //1 min
    //2 hr
    //3 date
    //4 month
    //5 week
    //6 year
    //7 wp
    getTime(datetime);
    //if(datetime[7] & 0x80){
    //  datetime[7] = 0;
    //  datetime[6] = 1;
    //  datetime[5] = 1;
    //  datetime[4] = 1;
    //  datetime[3] = 1;
    //  datetime[2] = 0;
    //  datetime[1] = 0;
    //  datetime[0] = 0;
    //  setTime(datetime);
    //}
    sprint(s, "wp,ww,yy/MM/dd HH:mm:ss\r\n");
    sprintByte(s, datetime[7]);
    sprint(s, ",");
    sprintByte(s, datetime[5]);
    sprint(s, ",");
    sprintByte(s, datetime[6]);
    sprint(s, "/");
    sprintByte(s, datetime[4]);
    sprint(s, "/");
    sprintByte(s, datetime[3]);
    sprint(s, " ");
    sprintByte(s, datetime[2]);
    sprint(s, ":");
    sprintByte(s, datetime[1]);
    sprint(s, ":");
    sprintByte(s, datetime[0]);
  }
  void dispose(){
    Form::dispose();
  }
  //int mouseEvent(int x, int y, int e){
  //  print("mouse\r\n");
  //}
  //int keyEvent(int key, int chr){
  //  print("key\r\n");
  //}

};
void Clock_close(Window* window){
}

void Clock_dispose(Window* self){
  ((Clock*)self)->dispose();
}

void Clock_draw(Window* self){
  ((Clock*)self)->draw();
}
